﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;

namespace CinemaBookingProject.DBLayer
{
    public class DBConnector
    {
        private SqlConnection conn = new SqlConnection("Data Source=balder.ucn.dk;Initial Catalog=dmaa0912_E8;Persist Security Info=True;User ID=dmaa0912_E8;Password=MaaGodt");

        /// <summary>
        /// Query = SQL Statement for den pågældende metode.
        /// </summary>
        /// <param name="query"></param>
        public DBConnector()
        {
            
        }

        public void Reader(string query)
        {
            //string[] rdrList;
            SqlDataReader rdr = null;
            try
            {

                conn.Open();

                SqlCommand cmd = new SqlCommand(query, conn);

                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Console.WriteLine(rdr[0]);
                }

            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
            //return rdrList;
        }

    }

}
